#include "led.h"

void led_fun(char *uled)
{
    uint8_t temp = 0x00;
    static uint8_t temp_old = 0xff;

    for (uint8_t i = 0; i < 8;i++)
        temp |= uled[i] << i;

        if(temp != temp_old)
        {
            GPIOC->ODR &= 0x00ff;
            GPIOC->ODR |= ~(temp << 8);

            GPIOD->BSRR |= 0x01 << 2;
            GPIOD->BRR |= 0x01 << 2;

            temp_old = temp;
        }
}

uint8_t uled[8] = {0,0,0,0,0,0,0,0};
uint16_t count;
void led_proc(void)
{
    
    if(error_count >= 3  )
    {
        uint32_t now_tim = HAL_GetTick();
        if (now_tim <= five_time_led_old + 5000)
        {
                count++;
            if(count >= 100){
                count = 0;
                uled[1] ^= 1;
            }
        }
        else
        {
            count = 0;
            uled[1] = 0;
        }
    }
    else
    {
        count = 0;
        uled[1] = 0;
    }
    led_fun(uled);
}